export default {
  data() {
    return {
      current: 0,
      list: [{
        name: '客户管理'
      },
        // {
        //   name: '客户营销'
        // }
      ],
      pageIndex: 1,
      keyword: '',
      list2: [],
      total: 0,
      pageIndex: 1,
      loadStatus: '',
    }
  },
  created() {
    this.getStoreCustomerList()
  },
  methods: {
    //点击搜索
    textSearch(){
      if(this.keyword===''){
        this.$u.toast('请输入关键字')
        return false
      }
      this.pageIndex = 1
      this.list2 = []
      this.getStoreCustomerList()
    },
    //搜索值改变
    changes(e){
      this.keyword = e
      if(e===''){
        this.keyword = ''
        this.pageIndex = 1
        this.list2 = []
        this.getStoreCustomerList()
      }
    },
    //上拉加载
    onReachBottom(){
      this.list2 = []
      this.pageIndex = 1
      this.getStoreCustomerList()
    },
    //加载更多
    more(){
      this.list2 = []
      this.pageIndex = 1
      this.getStoreCustomerList()
    },
    //搜索
    search(e){
      if(this.keyword===''){
        this.$u.toast('请输入关键字')
        return false
      }
      if(e.trim()){
        this.keyword = e
        this.list2 = []
        this.pageIndex = 1
        this.getStoreCustomerList()
      }
    },
    returnTime(time) {
      if (time) {
        return time.split('T')[0] + ' ' + time.split('T')[1]
      }
    },
    goPage(item) {
      let e = JSON.stringify(item)
      uni.navigateTo({
        url: '/pages_common/pages_index/archivesDetails/archivesDetails?list='+e
      })
    },
    change(index) {
      this.current = index
    },

    // 加载前、中、后
    moreStatus(status) {
		  this.loadStatus = status
    },
    //客户档案列表
    async getStoreCustomerList() {
      let storeId = uni.getStorageSync('userInfoDetail').store.storeId
      uni.showLoading({
			  title: '加载中'
      })
      this.loadStatus = 'loading'
      try {
        let data = {
          'pageIndex': this.pageIndex,
          'pageSize': 5,
          'store_Id': storeId,
          'search': this.keyword
        }
        const res = await this.$api.banner.getStoreCustomerList(data)
        // console.log(res)
        this.list2 = [...this.list2, ...res.data.list]
        this.total = res.data.total
        if(res.data.total <= 10){
				  this.loadStatus = 'nomore'
        }else{
				  this.moreStatus(res.data.list.length !== 0 ? 'loadmore' : 'nomore')
        }
        uni.hideLoading()
        if (res.data.list.length === 0) return false
        this.pageIndex += 1 // 当前页加1
      } catch (e) {
        //TODO handle the exception
      }
    },
  }
}
